#include <ebox_core.h>
#include "qrencode.h"
#include "qrcode_hmi.h"


QRcodeHMI::QRcodeHMI(HMI *display) {
    this->display = display;
}


void QRcodeHMI::init() {
    this->screenwidth = display->width;
    this->screenheight = display->height;
    display->fill_screen(WHITE);
    int min = screenwidth;
    if (screenheight<screenwidth)
        min = screenheight;
    multiply = min/WD;
    offsetsX = (screenwidth-(WD*multiply))/2;
    offsetsY = (screenheight-(WD*multiply))/2;
}
void QRcodeHMI::init(uint16_t x0,uint16_t y0,uint16_t width,uint16_t height) {
    this->screenwidth = width;
    this->screenheight = height;
    x_start = x0;
    y_start = y0;
    display->fill_rect(x0,y0,x0+width,y0+height,WHITE);
    int min = screenwidth;
    if (screenheight<screenwidth)
        min = screenheight;
    multiply = min/WD;
    offsetsX = (screenwidth-(WD*multiply))/2;
    offsetsY = (screenheight-(WD*multiply))/2;
}

void QRcodeHMI::screenwhite() {
    display->fill_rect(x_start,y_start,x_start+screenwidth,y_start+screenheight,WHITE);
}

void QRcodeHMI::screenupdate() {
    // No hay que hacer nada
}

void QRcodeHMI::drawPixel(int x, int y, int color) {
    if(color==1) {
        color = BLACK;
    } else {
        color = WHITE;
    }
    display->fill_rect(x_start+x,y_start+y,x_start+x+multiply,y_start+y+multiply,color);
}
